package cc.customer.web.aiResource;

import cc.customer.aiEmport.damain.CAiEmp;
import cc.customer.aiEmport.services.AiEmpServices;
import cc.customer.bigEmport.damain.IpRecords;
import cc.customer.bigEmport.services.BigEmpIrecords;
import cc.customer.common.domain.QueryRequest;
import cc.customer.common.domain.ResponseBo;
import cc.customer.common.utils.FileUtils;
import cc.customer.system.domain.MyUser;
import cc.customer.web.sys.controller.base.BaseController;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Description: customer
 * Created by yhsh on 2020/3/25 9:54
 * version 2.0
 * 方法说明
 */
@Controller
@RequestMapping(value = "aiExport")
public class AiExportController extends BaseController {


	@Autowired
	private AiEmpServices aiEmpServices;

	@Autowired
	private BigEmpIrecords bigEmpIrecords;

	/**加载AI名单批次导出名单**/
	@RequestMapping(value="/aiExportIndex")
	public String loadBigEpResoureIndex (){
		return "customer/aiEpResource/aiEpExport/AiEpExport_index_detail";
	}

	/**导出批次的类型**/
	@RequestMapping(value = "/exportDetail")
	public String  getExportDetail(){
		return "customer/aiEpResource/aiEpScreen/aiscreen_edetail";
	}


	/**获取导出当前批次的ai数据**/
	@RequestMapping("/getexportAiEmpbyUuid")
	@ResponseBody
	public Map<String, Object> getexportBigEmpbyUuid(QueryRequest request, String idsUuid, String condition){
		return super.selectByPageNumSize(request, () -> this.aiEmpServices.getallcAidByEmpUuid(idsUuid,condition));
	}
	/**获取批次的人员信息**/
	@RequestMapping(value = "/exportbatchUser")
	@ResponseBody
	public Map<String,Object> exportbatchUser(QueryRequest queryRequest,Long ipRecordIds){
		MyUser user = this.getCurrentUser();
		IpRecords records = this.bigEmpIrecords.getexportBatchCustomer(ipRecordIds);
		Map<String,Object> map =super.selectByPageNumSize(queryRequest,
				() -> this.aiEmpServices.getAllAiByempAllUuid(records.getcIpIds(),user));
		JSONObject json = JSONObject.parseObject(records.getcIpIcomdtion());
		map.put("condition",json);
		return map;
	}

	/**根据导出批次导出用户**/
	@RequestMapping("/exportAiEmpExcel")
	@ResponseBody
	public ResponseBo exportBigEmpExcel(Long kid){
		try {
			MyUser myUser = this.getCurrentUser();
			IpRecords records=  bigEmpIrecords.getexportBatchCustomer(kid);
			List<CAiEmp> list = this.aiEmpServices.getAllAiByempAllUuid(records.getcIpIds(),myUser);
			IpRecords ipRecords = new IpRecords();
			ipRecords.setcIpId(Integer.valueOf(kid+""));
			ipRecords.setcIpStatus("1");
			ResponseBo responseBo = FileUtils.createExcelByPOIKit("客户资料表", list, CAiEmp.class);
			bigEmpIrecords.updateExportBatchCustomer(ipRecords);
			return responseBo;
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseBo.error("导出Excel失败，请联系网站管理员！");
		}
	}


	/**根据导出批次导出用户**/
	@RequestMapping("/exportAiEmpExcelByuuid")
	@ResponseBody
	public ResponseBo exportAiEmpExcelByuuid(String keyids){
		try {
			MyUser myUser = this.getCurrentUser();
			List<CAiEmp> list = this.aiEmpServices.getAllAiByempAllUuid(keyids,myUser);
			ResponseBo responseBo = FileUtils.createExcelByPOIKit("客户资料表", list, CAiEmp.class);
			return responseBo;
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseBo.error("导出Excel失败，请联系网站管理员！");
		}
	}

}
